//
//  MBUserAccount.m
//  wensheng-sijicaifu
//
//  Created by kakarot on 2017/6/2.
//  Copyright © 2017年 kakarot. All rights reserved.
//

#import "MBUserAccount.h"

@implementation MBUserAccount

+ (instancetype)accontWithDict:(NSDictionary *)dict {
    return  [[self alloc] initWithDict:dict];

}

- (instancetype)initWithDict:(NSDictionary *)dict {
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {

}
//从文件中解析调用
- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        self.isUserValid = [aDecoder decodeBoolForKey:@"isUserValid"];
        self.interests = [aDecoder decodeObjectForKey:@"interests"];
        self.youAccept = [aDecoder decodeObjectForKey:@"youAccept"];
        self.userWant = [aDecoder decodeObjectForKey:@"userWant"];
        self.avatarUrl = [aDecoder decodeObjectForKey:@"avatarUrl"];
        self.socialConnections = [aDecoder decodeObjectForKey:@"socialConnections"];
        self.token = [aDecoder decodeObjectForKey:@"token"];
        self.nickName = [aDecoder decodeObjectForKey:@"nickName"];
        self.userFlag = [aDecoder decodeObjectForKey:@"userFlag"];
        self.birthday = [aDecoder decodeObjectForKey:@"birthday"];
        self.gender = [aDecoder decodeObjectForKey:@"gender"];
        self.lookingFor = [aDecoder decodeObjectForKey:@"lookingFor"];
        self.images = [aDecoder decodeObjectForKey:@"images"];
        self.aboutMe = [aDecoder decodeObjectForKey:@"aboutMe"];
        self.topic = [aDecoder decodeObjectForKey:@"topic"];
        self.rongCloudToken = [aDecoder decodeObjectForKey:@"rongCloudToken"];
        self.chatUserId = [aDecoder decodeObjectForKey:@"chatUserId"];
        self.age = [aDecoder decodeObjectForKey:@"age"];
        self.voiceArr = [aDecoder decodeObjectForKey:@"voiceArr"];
        self.kefuTargetId = [aDecoder decodeObjectForKey:@"kefuTargetId"];
        self.clothArr = [aDecoder decodeObjectForKey:@"clothArr"];
        self.vipDateStr = [aDecoder decodeObjectForKey:@"vipDateStr"];
        self.isLatest = [aDecoder decodeBoolForKey:@"isLatest"];
        self.isVip = [aDecoder decodeBoolForKey:@"isVip"];
        self.fcNum = [aDecoder decodeIntegerForKey:@"fcNum"];
        self.ppNum = [aDecoder decodeIntegerForKey:@"ppNum"];
        self.pvNum = [aDecoder decodeIntegerForKey:@"pvNum"];
        self.checkPPNum = [aDecoder decodeIntegerForKey:@"checkPPNum"];
        self.checkPVNum = [aDecoder decodeIntegerForKey:@"checkPVNum"];
        self.unReadNum = [aDecoder decodeIntForKey:@"unReadNum"];
        self.isUserType = [aDecoder decodeBoolForKey:@"isUserType"];
        self.isNewHome = [aDecoder decodeIntegerForKey:@"isNewHome"];
        self.isShowGuide = [aDecoder decodeBoolForKey:@"isShowGuide"];
        self.isShowFC = [aDecoder decodeBoolForKey:@"isShowFC"];
        self.modelListRefreshNum = [aDecoder decodeIntForKey:@"modelListRefreshNum"];
        self.todayStr = [aDecoder decodeObjectForKey:@"todayStr"];
        //check
        self.ppBuyArr = [aDecoder decodeObjectForKey:@"ppBuyArr"];
        self.pvBuyArr = [aDecoder decodeObjectForKey:@"pvBuyArr"];
        //掉单处理
        self.receiptDataArr = [aDecoder decodeObjectForKey:@"receiptDataArr"];
        //home/like
//        self.homeLikeDict = [aDecoder decodeObjectForKey:@"homeLikeDict"];
        self.likeNum = [aDecoder decodeIntegerForKey:@"likeNum"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder  encodeBool:self.isUserValid forKey:@"isUserValid"];
    [aCoder  encodeObject:self.interests forKey:@"interests"];
    [aCoder  encodeObject:self.youAccept forKey:@"youAccept"];
    [aCoder  encodeObject:self.userWant forKey:@"userWant"];
    [aCoder encodeObject:self.avatarUrl forKey:@"avatarUrl"];
    [aCoder encodeObject:self.token forKey:@"token"];
    [aCoder encodeObject:self.socialConnections forKey:@"socialConnections"];
    [aCoder encodeObject:self.nickName forKey:@"nickName"];
    [aCoder encodeObject:self.userFlag forKey:@"userFlag"];
    [aCoder encodeObject:self.birthday forKey:@"birthday"];
    [aCoder encodeObject:self.gender forKey:@"gender"];
    [aCoder encodeObject:self.lookingFor forKey:@"lookingFor"];
    [aCoder encodeObject:self.images forKey:@"images"];
    [aCoder encodeObject:self.aboutMe forKey:@"aboutMe"];
    [aCoder encodeObject:self.topic forKey:@"topic"];
    [aCoder encodeObject:self.rongCloudToken forKey:@"rongCloudToken"];
    [aCoder encodeObject:self.chatUserId forKey:@"chatUserId"];
    [aCoder encodeObject:self.age forKey:@"age"];
    [aCoder encodeObject:self.voiceArr forKey:@"voiceArr"];
    [aCoder encodeObject:self.kefuTargetId forKey:@"kefuTargetId"];
    [aCoder encodeObject:self.clothArr forKey:@"clothArr"];
    [aCoder encodeObject:self.vipDateStr forKey:@"vipDateStr"];
    [aCoder  encodeBool:self.isLatest forKey:@"isLatest"];
    [aCoder  encodeBool:self.isVip forKey:@"isVip"];
    [aCoder  encodeInteger:self.fcNum forKey:@"fcNum"];
    [aCoder  encodeInteger:self.ppNum forKey:@"ppNum"];
    [aCoder  encodeInteger:self.pvNum forKey:@"pvNum"];
    [aCoder  encodeInteger:self.checkPPNum forKey:@"checkPPNum"];
    [aCoder  encodeInteger:self.checkPVNum forKey:@"checkPVNum"];
    [aCoder  encodeInt:self.unReadNum forKey:@"unReadNum"];
    [aCoder  encodeBool:self.isUserType forKey:@"isUserType"];
    [aCoder  encodeInteger:self.isNewHome forKey:@"isNewHome"];
    [aCoder  encodeBool:self.isShowGuide forKey:@"isShowGuide"];
    [aCoder  encodeBool:self.isShowFC forKey:@"isShowFC"];
    [aCoder  encodeInt:self.modelListRefreshNum forKey:@"modelListRefreshNum"];
    [aCoder encodeObject:self.todayStr forKey:@"todayStr"];
    //check
    [aCoder encodeObject:self.ppBuyArr forKey:@"ppBuyArr"];
    [aCoder encodeObject:self.pvBuyArr forKey:@"pvBuyArr"];
    
    //掉单处理
    [aCoder encodeObject:self.receiptDataArr forKey:@"receiptDataArr"];
    //home/like
//    [aCoder encodeObject:self.homeLikeDict forKey:@"homeLikeDict"];
    [aCoder  encodeInteger:self.likeNum forKey:@"likeNum"];
}



+ (void)saveAccount:(MBUserAccount *)account {
    //后面要及时更新sessionId
    [NSKeyedArchiver archiveRootObject:account toFile:WSAccountFile];
}

+ (MBUserAccount *)defaultAccount {
    
    // 取出账号
    MBUserAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:WSAccountFile];
    // 判断sessionId是否过期
    return account;
}


// 删除归档
+ (BOOL)deleteDoc {
    NSError *error;
    BOOL success = [[NSFileManager defaultManager] removeItemAtPath:WSAccountFile error:&error];
    if (!success) {
        return NO;
    }
    return YES;
}
@end
